home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 426-450 / disk_438 / gadgeted / source / func.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  11KB  |  448 lines

  1. /*----------------------------------------------------------------------*
  2.    func.c Version 2.0 - © Copyright 1990 Jaba Development
  3.  
  4.    Author  : Jan van den Baard
  5.    Purpose : Special subroutines used by the program
  6.  *----------------------------------------------------------------------*/
  7.  
  8. extern struct GadgetList Gadgets;
  9. extern struct Gadget     *Gadget;
  10. extern struct Window     *MainWindow;
  11. extern struct Screen     *MainScreen;
  12. extern struct MemoryChain Memory;
  13. extern ULONG             Class;
  14. extern USHORT            FrontPen, GadgetCount, id, BackFill;
  15. extern BOOL              Saved;
  16. extern BOOL              REQUESTER;
  17.  
  18. /*
  19.  * gadgets, borders and texts for the 'Error' requester
  20.  */
  21. static SHORT MainPairs1[] =
  22.  { 2,1,307,1,307,37,2,37,2,1
  23.  };
  24. static struct Border MainBorder1 =
  25.  { 0,0,0,0,JAM1,5,MainPairs1,NULL
  26.  };
  27. static SHORT MainPairs[] =
  28.  { 2,0,307,0
  29.  };
  30. static struct Border MainBorder =
  31.  { 0,12,0,0,JAM1,2,MainPairs,&MainBorder1
  32.  };
  33. static SHORT CPairs[] =
  34.  { 0,0,111,0,111,10,0,10,0,0
  35.  };
  36. static struct Border CBorder =
  37.  { -1,-1,0,0,JAM1,5,CPairs,NULL
  38.  };
  39. static struct IntuiText CText =
  40.  { 0,0,JAM1,23,1,NULL,(UBYTE *)"CONTINUE",NULL
  41.  };
  42. static struct Gadget C =
  43.  { NULL,101,25,110,9,NULL,RELVERIFY,BOOLGADGET,
  44.    (APTR)&CBorder,NULL,&CText,NULL,NULL,NULL,NULL
  45.  };
  46. static struct IntuiText TText =
  47.  { 0,0,JAM1,63,3,NULL,(UBYTE *)"GadgetEd System Message",NULL
  48.  };
  49. static struct NewWindow err_req =
  50.  { 5,15,310,39,0,1,GADGETUP,NOCAREREFRESH+SMART_REFRESH+ACTIVATE+RMBTRAP,
  51.    NULL,NULL,NULL,NULL,NULL,0,0,0,0,CUSTOMSCREEN
  52.  };
  53.  
  54. /*
  55.  * gadgets, borders and texts for the 'Ask' Requester
  56.  */
  57. static SHORT MPairs2[] =
  58.  { 0,0,295,0,295,53,0,53,0,0
  59.  };
  60. static struct Border MBorder2 =
  61.  { 2,1,0,0,JAM1,5,MPairs2,NULL
  62.  };
  63. static SHORT MPairs1[] =
  64.  { 0,0,295,0
  65.  };
  66. static struct Border MBorder1 =
  67.  { 2,12,0,0,JAM1,2,MPairs1,&MBorder2
  68.  };
  69. static SHORT YNPairs[] =
  70.  { 0,0,126,0,126,12,0,12,0,0
  71.  };
  72. static struct Border YNBorder =
  73.  { -1,-1,0,0,JAM1,5,YNPairs,NULL
  74.  };
  75. static struct IntuiText YText =
  76.  { 0,0,JAM1,48,2,NULL,(UBYTE *)"YES",NULL
  77.  };
  78. static struct Gadget Y =
  79.  { NULL,11,38,125,11,NULL,RELVERIFY,BOOLGADGET,
  80.    (APTR)&YNBorder,NULL,&YText,NULL,NULL,0,NULL
  81.  };
  82. static struct IntuiText NText =
  83.  { 0,0,JAM1,55,2,NULL,(UBYTE *)"NO",NULL
  84.  };
  85. static struct Gadget N =
  86.  { &Y,162,38,125,11,NULL,RELVERIFY,BOOLGADGET,
  87.    (APTR)&YNBorder,NULL,&NText,NULL,NULL,1,NULL
  88.  };
  89. static struct IntuiText TTText =
  90.  { 0,0,JAM1,100,3,NULL,(UBYTE *)"Pleasy Verify",NULL
  91.  };
  92. static struct NewWindow ask_req =
  93.  { 10,15,300,56,0,1,GADGETUP,NOCAREREFRESH+SMART_REFRESH+ACTIVATE+RMBTRAP,
  94.    NULL,NULL,NULL,NULL,NULL,0,0,0,0,CUSTOMSCREEN
  95.  };
  96.  
  97. /*
  98.  * gadgets, borders and texts for the 'About' Requester
  99.  */
  100. static SHORT ABPairs2[] =
  101.  { 0,0,295,0
  102.  };
  103. static struct Border ABBorder2 =
  104.  { 2,12,0,0,JAM1,2,ABPairs2,NULL
  105.  };
  106. static SHORT ABPairs1[] =
  107.  { 0,0,295,0,295,67,0,67,0,0
  108.  };
  109. static struct Border ABBorder1 =
  110.  { 2,1,0,0,JAM1,5,ABPairs1,&ABBorder2
  111.  };
  112. static struct IntuiText ABText4 =
  113.  { 0,0,JAM1,78,38,NULL,(UBYTE *)"Jan van den Baard",NULL
  114.  };
  115. static struct IntuiText ABText3 =
  116.  { 0,0,JAM1,40,27,NULL,(UBYTE *)"written in Aztec C V5.0a by",&ABText4
  117.  };
  118. static struct IntuiText ABText2 =
  119.  { 0,0,JAM1,9,17,NULL,(UBYTE *)"(c) Copyright 1990 Jaba Development",&ABText3
  120.  };
  121. static struct IntuiText ABText1 =
  122.  { 0,0,JAM1,54,3,NULL,(UBYTE *)"- GadgetEd Version 2.0 -",&ABText2
  123.  };
  124. static SHORT CONTPairs[] =
  125.  { 0,0,157,0,157,16,0,16,0,0
  126.  };
  127. static struct Border CONTBorder =
  128.  { -1,-1,0,0,JAM1,5,CONTPairs,NULL
  129.  };
  130. static struct IntuiText CONTText =
  131.  { 0,0,JAM1,48,4,NULL,(UBYTE *)"CONTINUE",NULL
  132.  };
  133. static struct Gadget CONT =
  134.  { NULL,68,49,156,15,NULL,RELVERIFY,BOOLGADGET,
  135.    (APTR)&CONTBorder,NULL,&CONTText,NULL,NULL,NULL,NULL
  136.  };
  137. static struct NewWindow ab_req =
  138.  { 10,15,300,70,0,1,GADGETUP,SMART_REFRESH+NOCAREREFRESH+ACTIVATE+RMBTRAP,
  139.    NULL,NULL,NULL,NULL,NULL,0,0,0,0,CUSTOMSCREEN
  140.  };
  141.  
  142. /*
  143.  * draw the graphics of the window
  144.  */
  145. VOID draw(window,gadget,border,itext)
  146.     struct Window    *window;
  147.     struct Gadget    *gadget;
  148.     struct Border    *border;
  149.     struct IntuiText *itext;
  150. {
  151.     struct RastPort *rp;
  152.     register struct Gadget   *g, *g1;
  153.     register USHORT x,y,x1,y1;
  154.  
  155.     rp = window->RPort;
  156.     SetDrMd(rp,JAM1);
  157.     SetAPen(rp,1);
  158.     RectFill(rp,0,0,window->Width,window->Height);
  159.  
  160.     g = gadget;
  161.     while(1)
  162.     {   if(TestBits((ULONG)g->GadgetType,STRGADGET))
  163.         {   x = g->LeftEdge; y = g->TopEdge;
  164.             x1 = x + g->Width; y1 = y + g->Height;
  165.             RectFill(rp,x,y,x1,y1);
  166.         }
  167.         g1 = g->NextGadget;
  168.         if((TestBits((ULONG)g->GadgetType,BOOLGADGET)) AND
  169.            (NOT TestBits((ULONG)g->GadgetType,GADGET0002)))
  170.                ShadowGadget(window,g,NULL,0);
  171.         if(NOT g1) break;
  172.         g = g1;
  173.     }
  174.     PrintIText(rp,itext,0,0);
  175.     DrawBorder(rp,border,0,0);
  176.     AddGList(window,gadget,-1L,-1L,NULL);
  177.     RefreshGList(gadget,window,NULL,-1L);
  178. }
  179.  
  180. /*
  181.  * put up the error window
  182.  */
  183. VOID Error(message)
  184.     UBYTE         *message;
  185. {
  186.     struct Window *erw;
  187.  
  188.     err_req.Screen = MainScreen;
  189.     if(NOT(erw = OpenWindow(&err_req))) return;
  190.     draw(erw,&C,&MainBorder,&TText);
  191.     ok();
  192.     SetDrMd(erw->RPort,JAM1);
  193.     SetAPen(erw->RPort,2);
  194.     Move(erw->RPort,155-(strlen((char *)message) << 2),21);
  195.     Text(erw->RPort,(char *)message,strlen((char *)message));
  196.     disable_window();
  197.     do
  198.     {   Wait(1 << erw->UserPort->mp_SigBit);
  199.         while(read_msg(erw));
  200.     } while(Class != GADGETUP);
  201.     CloseWindow(erw);
  202.     enable_window();
  203. }
  204.  
  205. /*
  206.  * add a border to gadget 'g'
  207.  */
  208. BOOL add_border(g)
  209.     struct Gadget *g;
  210. {
  211.     register SHORT *XY;
  212.     SHORT           x,y,w,h;
  213.     struct Border  *border;
  214.  
  215.     x = g->LeftEdge - 1;
  216.     y = g->TopEdge  - 1;
  217.     w = g->Width;
  218.     h = g->Height;
  219.  
  220.     if(NOT(border = (struct Border *)Alloc(&Memory,sizeof(struct Border))))
  221.         return(FALSE);
  222.     if(NOT(XY = (SHORT *)Alloc(&Memory,(ULONG)20)))
  223.         return(FALSE);
  224.  
  225.     XY[0] = XY[1] = XY[3] = XY[6] = XY[8] = XY[9] = -1;
  226.     XY[2] = XY[4] = w;
  227.     XY[5] = XY[7] = h;
  228.  
  229.     border->FrontPen     = FrontPen;
  230.     border->DrawMode     = JAM1;
  231.     border->Count        = 5;
  232.     border->XY           = XY;
  233.  
  234.     g->GadgetRender = (APTR)border;
  235.     return(TRUE);
  236. }
  237.  
  238. /*
  239.  * add a gadget to the edit window and to the list
  240.  */
  241. VOID add_gadget(w,x,y,x1,y1)
  242.     struct Window *w;
  243.     SHORT          x,y,x1,y1;
  244. {
  245.     SHORT tmp;
  246.     struct MyGadget *gadget;
  247.  
  248.     Saved = FALSE;
  249.  
  250.     if(x > x1) { tmp = x; x = x1; x1 = tmp; }
  251.     if(y > y1) { tmp = y; y = y1; y1 = tmp; }
  252.  
  253.     if(((x1 - x) < 9) OR ((y1 - y) < 9))
  254.     {   draw_box(w,x,y,x1,y1);
  255.         Error("Gadget to small !");
  256.         return;
  257.     }
  258.  
  259.     if(NOT(gadget = (struct MyGadget *)Alloc(&Memory,sizeof(struct MyGadget))))
  260.     {   Error("Out of memory !");
  261.         return;
  262.     }
  263.  
  264.     AddHead((void *)&Gadgets,(void *)gadget);
  265.  
  266.     gadget->Gadget.GadgetType      = BOOLGADGET;
  267.     gadget->Gadget.Flags           = GADGHCOMP;
  268.     gadget->Gadget.Activation      = RELVERIFY;
  269.  
  270.     gadget->Gadget.LeftEdge        = x + 1;
  271.     gadget->Gadget.TopEdge         = y + 1;
  272.     gadget->Gadget.Width           = (x1 - x) - 1;
  273.     gadget->Gadget.Height          = (y1 - y) - 1;
  274.  
  275.     gadget->Gadget.GadgetID        = GadgetCount++;
  276.  
  277.     if(NOT(add_border(&gadget->Gadget)))
  278.     {   RemHead((void *)&Gadgets);
  279.         FreeGadget(gadget);
  280.         Error("Out of memory !");
  281.         return;
  282.     }
  283.  
  284.     AddGList(w,&gadget->Gadget,-1L,1,NULL);
  285.     RefreshGList(&gadget->Gadget,w,NULL,1);
  286.     Format((char *)&gadget->GadgetLabel,"Gadget%ld",id++);
  287. }
  288.  
  289. /*
  290.  * set the absolute dimensions of a 'GREL' gadget
  291.  */
  292. VOID un_grel(wi,g)
  293.     struct Window *wi;
  294.     struct Gadget *g;
  295. {
  296.     SHORT l,t,w,h,ww,wh;
  297.  
  298.     l = g->LeftEdge - 1;
  299.     t = g->TopEdge  - 1;
  300.     w = g->Width    - 1;
  301.     h = g->Height   - 1;
  302.  
  303.     if(TestBits((ULONG)wi->Flags,GIMMEZEROZERO))
  304.     {   ww = wi->GZZWidth;
  305.         wh = wi->GZZHeight;
  306.     }
  307.     else
  308.     {   ww = wi->Width;
  309.         wh = wi->Height;
  310.     }
  311.  
  312.     if(TestBits((ULONG)g->Flags,GRELBOTTOM))
  313.         g->TopEdge  = t + wh;
  314.     if(TestBits((ULONG)g->Flags,GRELRIGHT))
  315.         g->LeftEdge = l + ww;
  316.     if(TestBits((ULONG)g->Flags,GRELWIDTH))
  317.         g->Width    = (w + ww) + 1;
  318.     if(TestBits((ULONG)g->Flags,GRELHEIGHT))
  319.         g->Height   = (h + wh) + 1;
  320. }
  321.  
  322. /*
  323.  * set the relative dimensions of a 'GREL' gadget
  324.  */
  325. VOID grel(wi,g)
  326.     struct Window *wi;
  327.     struct Gadget *g;
  328. {
  329.     SHORT l,t,w,h,ww,wh;
  330.  
  331.     l = g->LeftEdge + 1;
  332.     t = g->TopEdge  + 1;
  333.     w = g->Width    - 1;
  334.     h = g->Height   - 1;
  335.  
  336.     if(TestBits((ULONG)wi->Flags,GIMMEZEROZERO))
  337.     {   ww = wi->GZZWidth;
  338.         wh = wi->GZZHeight;
  339.     }
  340.     else
  341.     {   ww = wi->Width;
  342.         wh = wi->Height;
  343.     }
  344.  
  345.     if(TestBits((ULONG)g->Flags,GRELBOTTOM))
  346.         g->TopEdge  = t - wh;
  347.     if(TestBits((ULONG)g->Flags,GRELRIGHT))
  348.         g->LeftEdge = l - ww;
  349.     if(TestBits((ULONG)g->Flags,GRELWIDTH))
  350.         g->Width    = (w - ww) + 1;
  351.     if(TestBits((ULONG)g->Flags,GRELHEIGHT))
  352.         g->Height   = (h - wh) + 1;
  353. }
  354.  
  355. /*
  356.  * erase a gadget from the display
  357.  * I don't use the function of the tool.library because
  358.  * requesters are not used by GadgetEd and erasing a gadget on
  359.  * a 'requester' edit window needs the backfill color.
  360.  */
  361. VOID erase_gadget(wi,g)
  362.     struct Window *wi;
  363.     struct Gadget *g;
  364. {
  365.     SHORT                     x,y,x1,y1;
  366.     register struct IntuiText *it;
  367.     struct IntuiText          i;
  368.     struct RastPort           *rp = wi->RPort;
  369.  
  370.     SetAPen(rp,0);
  371.     if(REQUESTER) SetAPen(rp,BackFill);
  372.     SetDrMd(rp,JAM1);
  373.     RefreshGList(g,wi,NULL,1);
  374.     x  = g->LeftEdge - 1;
  375.     y  = g->TopEdge  - 1;
  376.     x1 = x + g->Width + 1;
  377.     y1 = y + g->Height + 1;
  378.  
  379.     RectFill(rp,x,y,x1,y1);
  380.     if((it = g->GadgetText))
  381.     {   while(1)
  382.         {   CopyMem((char *)it,(char *)&i,sizeof(struct IntuiText));
  383.             i.FrontPen = i.BackPen = 0;
  384.             if(REQUESTER) i.FrontPen = i.BackPen = BackFill;
  385.             i.NextText = NULL;
  386.             i.DrawMode = JAM2;
  387.             PrintIText(rp,&i,x+1,y+1);
  388.             if(NOT(it = it->NextText)) break;
  389.         }
  390.     }
  391. }
  392.  
  393. /*
  394.  * put up the ask window
  395.  */
  396. LONG Ask(text,text1)
  397.     UBYTE         *text, *text1;
  398. {
  399.     USHORT y,id;
  400.     BOOL   ret;
  401.     struct Window *aw;
  402.     struct RastPort *rp;
  403.  
  404.     if(text1) y = 21;
  405.     else      y = 27;
  406.     ask_req.Screen = MainScreen;
  407.     if(NOT(aw = OpenWindow(&ask_req))) return;
  408.     rp = aw->RPort;
  409.     draw(aw,&N,&MBorder1,&TTText);
  410.     SetDrMd(rp,JAM1);
  411.     SetAPen(rp,2);
  412.     Move(rp,150-((strlen((char *)text) << 3) >> 1),y);
  413.     Text(rp,(char *)text,strlen((char *)text));
  414.     if(text1)
  415.     {   Move(rp,150-((strlen((char *)text1) << 3) >> 1),y+10);
  416.         Text(rp,(char *)text1,strlen((char *)text1));
  417.     }
  418.     disable_window();
  419.     do
  420.     {   Wait(1 << aw->UserPort->mp_SigBit);
  421.         while(read_msg(aw));
  422.        id = Gadget->GadgetID;
  423.     } while(Class != GADGETUP);
  424.     CloseWindow(aw);
  425.     if(id == 1) ret = FALSE;
  426.     else ret = TRUE;
  427.     enable_window();
  428.     return(ret);
  429. }
  430.  
  431. /*
  432.  * put up the about window
  433.  */
  434. VOID About()
  435. {
  436.     struct Window *abw;
  437.     ab_req.Screen = MainScreen;
  438.     if(NOT(abw = OpenWindow(&ab_req))) return;
  439.     draw(abw,&CONT,&ABBorder1,&ABText1);
  440.     disable_window();
  441.     do
  442.     {   Wait(1 << abw->UserPort->mp_SigBit);
  443.         while(read_msg(abw));
  444.     } while(Class != GADGETUP);
  445.     CloseWindow(abw);
  446.     enable_window();
  447. }
  448.